//
//  UserInfoModel.m
//
//  Created by   on 2019/6/4
//  Copyright (c) 2019 __MyCompanyName__. All rights reserved.
//

#import "UserInfoModel.h"


NSString *const kUserInfoModelId = @"id";
NSString *const kUserInfoModelUserNickname = @"userNickname";
NSString *const kUserInfoModelUserMenstrualCycle = @"userMenstrualCycle";
NSString *const kUserInfoModelUserMac = @"userMac";
NSString *const kUserInfoModelUserMenstrualLastBeanDay = @"userMenstrualLastBeanDay";
NSString *const kUserInfoModelUserPostnatalDate = @"userPostnatalDate";
NSString *const kUserInfoModelUserPassword = @"userPassword";
NSString *const kUserInfoModelUserWeight = @"userWeight";
NSString *const kUserInfoModelUserIcon = @"userIcon";
NSString *const kUserInfoModelUserMenstrualDays = @"userMenstrualDays";
NSString *const kUserInfoModelIsDelete = @"isDelete";
NSString *const kUserInfoModelUserName = @"userName";
NSString *const kUserInfoModelUserSignature = @"userSignature";
NSString *const kUserInfoModelUserChildren = @"userChildren";
NSString *const kUserInfoModelUserChildbirthType = @"userChildbirthType";
NSString *const kUserInfoModelUserMobile = @"userMobile";
NSString *const kUserInfoModelAddTime = @"addTime";
NSString *const kUserInfoModelUserBirthday = @"userBirthday";
NSString *const kUserInfoModelUserChildbirth = @"userChildbirth";


@interface UserInfoModel ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation UserInfoModel

@synthesize internalBaseClassIdentifier = _internalBaseClassIdentifier;
@synthesize userNickname = _userNickname;
@synthesize userMenstrualCycle = _userMenstrualCycle;
@synthesize userMac = _userMac;
@synthesize userMenstrualLastBeanDay = _userMenstrualLastBeanDay;
@synthesize userPostnatalDate = _userPostnatalDate;
@synthesize userPassword = _userPassword;
@synthesize userWeight = _userWeight;
@synthesize userIcon = _userIcon;
@synthesize userMenstrualDays = _userMenstrualDays;
@synthesize isDelete = _isDelete;
@synthesize userName = _userName;
@synthesize userSignature = _userSignature;
@synthesize userChildren = _userChildren;
@synthesize userChildbirthType = _userChildbirthType;
@synthesize userMobile = _userMobile;
@synthesize addTime = _addTime;
@synthesize userBirthday = _userBirthday;
@synthesize userChildbirth = _userChildbirth;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.internalBaseClassIdentifier = [self objectOrNilForKey:kUserInfoModelId fromDictionary:dict];
            self.userNickname = [self objectOrNilForKey:kUserInfoModelUserNickname fromDictionary:dict];
            self.userMenstrualCycle = [self objectOrNilForKey:kUserInfoModelUserMenstrualCycle fromDictionary:dict];
            self.userMac = [self objectOrNilForKey:kUserInfoModelUserMac fromDictionary:dict];
            self.userMenstrualLastBeanDay = [self objectOrNilForKey:kUserInfoModelUserMenstrualLastBeanDay fromDictionary:dict];
            self.userPostnatalDate = [self objectOrNilForKey:kUserInfoModelUserPostnatalDate fromDictionary:dict];
            self.userPassword = [self objectOrNilForKey:kUserInfoModelUserPassword fromDictionary:dict];
            self.userWeight = [self objectOrNilForKey:kUserInfoModelUserWeight fromDictionary:dict];
            self.userIcon = [self objectOrNilForKey:kUserInfoModelUserIcon fromDictionary:dict];
            self.userMenstrualDays = [self objectOrNilForKey:kUserInfoModelUserMenstrualDays fromDictionary:dict];
            self.isDelete = [[self objectOrNilForKey:kUserInfoModelIsDelete fromDictionary:dict] boolValue];
            self.userName = [self objectOrNilForKey:kUserInfoModelUserName fromDictionary:dict];
            self.userSignature = [self objectOrNilForKey:kUserInfoModelUserSignature fromDictionary:dict];
            self.userChildren = [self objectOrNilForKey:kUserInfoModelUserChildren fromDictionary:dict];
            self.userChildbirthType = [self objectOrNilForKey:kUserInfoModelUserChildbirthType fromDictionary:dict];
            self.userMobile = [self objectOrNilForKey:kUserInfoModelUserMobile fromDictionary:dict];
            self.addTime = [[self objectOrNilForKey:kUserInfoModelAddTime fromDictionary:dict] doubleValue];
            self.userBirthday = [self objectOrNilForKey:kUserInfoModelUserBirthday fromDictionary:dict];
            self.userChildbirth = [self objectOrNilForKey:kUserInfoModelUserChildbirth fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.internalBaseClassIdentifier forKey:kUserInfoModelId];
    [mutableDict setValue:self.userNickname forKey:kUserInfoModelUserNickname];
    [mutableDict setValue:self.userMenstrualCycle forKey:kUserInfoModelUserMenstrualCycle];
    [mutableDict setValue:self.userMac forKey:kUserInfoModelUserMac];
    [mutableDict setValue:self.userMenstrualLastBeanDay forKey:kUserInfoModelUserMenstrualLastBeanDay];
    [mutableDict setValue:self.userPostnatalDate forKey:kUserInfoModelUserPostnatalDate];
    [mutableDict setValue:self.userPassword forKey:kUserInfoModelUserPassword];
    [mutableDict setValue:self.userWeight forKey:kUserInfoModelUserWeight];
    [mutableDict setValue:self.userIcon forKey:kUserInfoModelUserIcon];
    [mutableDict setValue:self.userMenstrualDays forKey:kUserInfoModelUserMenstrualDays];
    [mutableDict setValue:[NSNumber numberWithBool:self.isDelete] forKey:kUserInfoModelIsDelete];
    [mutableDict setValue:self.userName forKey:kUserInfoModelUserName];
    [mutableDict setValue:self.userSignature forKey:kUserInfoModelUserSignature];
    [mutableDict setValue:self.userChildren forKey:kUserInfoModelUserChildren];
    [mutableDict setValue:self.userChildbirthType forKey:kUserInfoModelUserChildbirthType];
    [mutableDict setValue:self.userMobile forKey:kUserInfoModelUserMobile];
    [mutableDict setValue:[NSNumber numberWithDouble:self.addTime] forKey:kUserInfoModelAddTime];
    [mutableDict setValue:self.userBirthday forKey:kUserInfoModelUserBirthday];
    [mutableDict setValue:self.userChildbirth forKey:kUserInfoModelUserChildbirth];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.internalBaseClassIdentifier = [aDecoder decodeObjectForKey:kUserInfoModelId];
    self.userNickname = [aDecoder decodeObjectForKey:kUserInfoModelUserNickname];
    self.userMenstrualCycle = [aDecoder decodeObjectForKey:kUserInfoModelUserMenstrualCycle];
    self.userMac = [aDecoder decodeObjectForKey:kUserInfoModelUserMac];
    self.userMenstrualLastBeanDay = [aDecoder decodeObjectForKey:kUserInfoModelUserMenstrualLastBeanDay];
    self.userPostnatalDate = [aDecoder decodeObjectForKey:kUserInfoModelUserPostnatalDate];
    self.userPassword = [aDecoder decodeObjectForKey:kUserInfoModelUserPassword];
    self.userWeight = [aDecoder decodeObjectForKey:kUserInfoModelUserWeight];
    self.userIcon = [aDecoder decodeObjectForKey:kUserInfoModelUserIcon];
    self.userMenstrualDays = [aDecoder decodeObjectForKey:kUserInfoModelUserMenstrualDays];
    self.isDelete = [aDecoder decodeBoolForKey:kUserInfoModelIsDelete];
    self.userName = [aDecoder decodeObjectForKey:kUserInfoModelUserName];
    self.userSignature = [aDecoder decodeObjectForKey:kUserInfoModelUserSignature];
    self.userChildren = [aDecoder decodeObjectForKey:kUserInfoModelUserChildren];
    self.userChildbirthType = [aDecoder decodeObjectForKey:kUserInfoModelUserChildbirthType];
    self.userMobile = [aDecoder decodeObjectForKey:kUserInfoModelUserMobile];
    self.addTime = [aDecoder decodeDoubleForKey:kUserInfoModelAddTime];
    self.userBirthday = [aDecoder decodeObjectForKey:kUserInfoModelUserBirthday];
    self.userChildbirth = [aDecoder decodeObjectForKey:kUserInfoModelUserChildbirth];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_internalBaseClassIdentifier forKey:kUserInfoModelId];
    [aCoder encodeObject:_userNickname forKey:kUserInfoModelUserNickname];
    [aCoder encodeObject:_userMenstrualCycle forKey:kUserInfoModelUserMenstrualCycle];
    [aCoder encodeObject:_userMac forKey:kUserInfoModelUserMac];
    [aCoder encodeObject:_userMenstrualLastBeanDay forKey:kUserInfoModelUserMenstrualLastBeanDay];
    [aCoder encodeObject:_userPostnatalDate forKey:kUserInfoModelUserPostnatalDate];
    [aCoder encodeObject:_userPassword forKey:kUserInfoModelUserPassword];
    [aCoder encodeObject:_userWeight forKey:kUserInfoModelUserWeight];
    [aCoder encodeObject:_userIcon forKey:kUserInfoModelUserIcon];
    [aCoder encodeObject:_userMenstrualDays forKey:kUserInfoModelUserMenstrualDays];
    [aCoder encodeBool:_isDelete forKey:kUserInfoModelIsDelete];
    [aCoder encodeObject:_userName forKey:kUserInfoModelUserName];
    [aCoder encodeObject:_userSignature forKey:kUserInfoModelUserSignature];
    [aCoder encodeObject:_userChildren forKey:kUserInfoModelUserChildren];
    [aCoder encodeObject:_userChildbirthType forKey:kUserInfoModelUserChildbirthType];
    [aCoder encodeObject:_userMobile forKey:kUserInfoModelUserMobile];
    [aCoder encodeDouble:_addTime forKey:kUserInfoModelAddTime];
    [aCoder encodeObject:_userBirthday forKey:kUserInfoModelUserBirthday];
    [aCoder encodeObject:_userChildbirth forKey:kUserInfoModelUserChildbirth];
}

- (id)copyWithZone:(NSZone *)zone
{
    UserInfoModel *copy = [[UserInfoModel alloc] init];
    
    if (copy) {

        copy.internalBaseClassIdentifier = [self.internalBaseClassIdentifier copyWithZone:zone];
        copy.userNickname = [self.userNickname copyWithZone:zone];
        copy.userMenstrualCycle = [self.userMenstrualCycle copyWithZone:zone];
        copy.userMac = [self.userMac copyWithZone:zone];
        copy.userMenstrualLastBeanDay = [self.userMenstrualLastBeanDay copyWithZone:zone];
        copy.userPostnatalDate = [self.userPostnatalDate copyWithZone:zone];
        copy.userPassword = [self.userPassword copyWithZone:zone];
        copy.userWeight = [self.userWeight copyWithZone:zone];
        copy.userIcon = [self.userIcon copyWithZone:zone];
        copy.userMenstrualDays = [self.userMenstrualDays copyWithZone:zone];
        copy.isDelete = self.isDelete;
        copy.userName = [self.userName copyWithZone:zone];
        copy.userSignature = [self.userSignature copyWithZone:zone];
        copy.userChildren = [self.userChildren copyWithZone:zone];
        copy.userChildbirthType = [self.userChildbirthType copyWithZone:zone];
        copy.userMobile = [self.userMobile copyWithZone:zone];
        copy.addTime = self.addTime;
        copy.userBirthday = [self.userBirthday copyWithZone:zone];
        copy.userChildbirth = [self.userChildbirth copyWithZone:zone];
    }
    
    return copy;
}


@end
